﻿using DAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.WebPages;

namespace DataProj.Areas.BackSys.ServiceTools
{
    public class MySession
    {
        /// <summary>
        /// 写Session
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public static void WriteSession<T>(string key, T value)
        {
            if (key.IsEmpty())
                return;
            HttpContext.Current.Session[key] = value;
        }


        //public static (string,string) GetLoginTypeAndName(){
        //      string loginType = string.Empty;
        //      string userName = string.Empty;
        //    if (MySession.GetSession("detail") != null && MySession.GetSession("loginType") != null)
        //    {
        //        loginType = MySession.GetSession("loginType").ToString();
        //        switch (loginType)
        //        {
        //            case "管理员":
        //                userName = (MySession.GetSession("detail") as Manager).UserName;
        //                break;
        //            case "快递员":
        //                userName = (MySession.GetSession("detail") as Deliveryman).UserName;
        //                break;
        //            case "用户":
        //                userName = (MySession.GetSession("detail") as UserInfo).UserName;
        //                break;
        //            default:
        //                break;
        //        }
        //    }
        //    return (loginType,userName);    

        //}


        /// <summary>
        /// 读取Session (字符串类)
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static UserInfo GetSession_UserInfo(string key)
        {
            if (key.IsEmpty())
                return null;
            return HttpContext.Current.Session[key] as UserInfo;
        }

        /// <summary>
        /// 读取Session (字符串类)
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static Manager GetSession_ManagerInfo(string key)
        {
            if (key.IsEmpty())
                return null;
            return HttpContext.Current.Session[key] as Manager;
        }



        /// <summary>
        /// 读取Session (字符串类)
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static Deliveryman GetSession_DeliverymanInfo(string key)
        {
            if (key.IsEmpty())
                return null;
            return HttpContext.Current.Session[key] as Deliveryman;
        }


        public static void Abandon()
        {
            HttpContext.Current.Session.Abandon();
        }


        /// <summary>
        /// 读取Session (object类)
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetSession(string key)
        {
            if (key.IsEmpty()|| HttpContext.Current==null||HttpContext.Current.Session[key]==null)
                return string.Empty;
            return HttpContext.Current.Session[key].ToString();
        }
        /// <summary>
        /// 删除Session
        /// </summary>
        /// <param name="key"></param>
        public static void RemoveSession(string key)
        {
            if (key.IsEmpty())
                return;
            HttpContext.Current.Session.Contents.Remove(key);
        }


    }
}